package com.hzqx.xxzx.framework;

import java.awt.image.BufferedImage;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hzqx.xxzx.framework.listener.MyHttpSessionListener;
import com.hzqx.xxzx.framework.oss.OSSClient;
import com.hzqx.xxzx.framework.oss.OSSUploadFileResponse;
import com.hzqx.xxzx.framework.utils.QuickMarkUtil;

@RestController
public class TestController {
	@Autowired
	private OSSClient oSSClient;
	
	@GetMapping("oss")
	public String uploadOss() {
		try {
			BufferedImage greenBufferedImage = QuickMarkUtil.buildBlueQuickMarkImage("https://www.baidu.com");
			//QuickMarkUtil.writeToLocal("E:/flm/greenbaidu.JPG", greenBufferedImage);
			InputStream stream = QuickMarkUtil.bufferedImageToInputStream(greenBufferedImage);
			OSSUploadFileResponse ossUploadFileResponse = oSSClient.putObject(stream);
			System.out.println(ossUploadFileResponse.toString());
			
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		return "123";
	}
	
	
	
	@GetMapping("addSession")
    public String addSession(HttpServletRequest request) {
        HttpSession session = request.getSession();
        session.setAttribute("name", "haixiang");
        return "当前在线人数" + session.getServletContext().getAttribute("sessionCount") + "人";
    }

    @GetMapping("removeSession")
    public String removeSession(HttpServletRequest request) {
        HttpSession session = request.getSession();
        session.invalidate();
        return "当前在线人数" + session.getServletContext().getAttribute("sessionCount") + "人";
    }

    @GetMapping("online")
    public String online() {
        return "当前在线人数" + MyHttpSessionListener.userCount.get() + "人";
    }


}
